package gov.nasa.anml.lifted;

import java.util.ArrayList;

import gov.nasa.anml.*;
import gov.nasa.anml.utility.*;
import gov.nasa.anml.PDDL;

//really this is a function binding

// Bind<Action,SimpleBoolean,SimpleVoid> is also a good choice, but technically one thing does actually modify
// the implicit predicate, so there is a non-void history to be concerned about.
public class ActionReference extends Bind<Action,SimpleBoolean,SimpleBoolean> {

	public ActionReference() {}

	public ActionReference(Action ref) {
		super(ref);
	}

	// could make a pool of various arity arrays to avoid garbage collection
	// and memory bloat simultaneously	
	public SimpleBoolean value(State s) {
		// use setArgs(s) to find the instantiation of the action
		// that is being tested to see if it is executing in s
		return ANMLBoolean.False;
	}

	public TypeCode typeCode() {
		return TypeCode.Boolean;
	}

	public History<SimpleBoolean> storage(State p, State c) {
		// maybe return a Step object?
		return null;
	}

	public boolean apply(State p, int contextID, State c) {
		// TODO: use setArgs() to set the parameters of the action up
		return ref.apply(p,contextID,c);
	}

	public transient PDDL.BooleanExpression asPDDLBooleanCondition;
	public transient PDDL.PredicateReference refPDDL;
	

	public PDDL.Expression translateExpr(PDDL pddl, Interval unit) {
		if (refPDDL != null)
			return refPDDL;
		refPDDL = pddl.new PredicateReference(this.ref.makePDDLExecuting());
		// need a new reference (rather than this.ref.trivialSelfRelf or whatever its called) because arguments != formal parameters
		for (Expression<? extends SimpleObject<?>,?> e : this.arguments) {
			PDDL.Argument a = e.translateArgument(pddl,unit);
			if (a != null)
				refPDDL.arguments.add(a);
		}
		return refPDDL;
	}





}


